<?php
/**
 * //w/w/w.s/h/u/o/t//u/p/u c/o/m  说/图/谱/源/码/分/享
 */
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/7/24 0024
 * Time: 15:52
 */
defined("IN_IA") or exit("Access Denied");
checklogin();  //验证是否登录
global $_W,$_GPC;
$uniacid=$_W['uniacid'];
$op=$_GPC['op'] ? $_GPC['op'] : "webThingsSet";
if($op=='webThingsSet'){
    $condition=array(
        'ikey'=>array('is_open_webthing','webthing_username','webthing_password','webthing_appid'),
        'uniacid'=>$uniacid,
    );
    $nowList=pdo_getall('cqkundian_farm_set',$condition);
    $list=array();
    foreach ($nowList as $key => $value) {
        $list[$value['ikey']]=$value['value'];
    }
    include $this->template('web/webThing/webThingsSet');
}

//保存物联网设置信息
if($op=='webThingsSetSave'){
    $data=$_POST;
    if(empty($data['is_open_webthing'])){
        $data['is_open_webthing']=0;
    }
    $res=0;
    foreach ($data as $key=>$v){
        $updateData=array(
            'ikey'=>$key,
            'value'=>$v,
            'uniacid'=>$uniacid,
        );
        $cond=array(
            'ikey'=>$key,
            'uniacid'=>$uniacid,
        );
        $farmData=pdo_get('cqkundian_farm_set',$cond);
        if(empty($farmData)){
            $res+=pdo_insert('cqkundian_farm_set',$updateData);
        }else{
            $res+=pdo_update('cqkundian_farm_set',$updateData,$cond);
        }
    }
    if($res){
        message('操作成功',url('site/entry/webThing',array('m'=>'kundian_farm','op'=>'webThingsSet')));die;
    }else{
        message('操作失败');
    }
}